
import 'package:flutter/material.dart';
import 'package:zfth/pages/smokeAlarm/SmokeAlarmHandleList.dart';
import 'package:zfth/pages/smokeAlarm/SmokeAlarmLogList.dart';
import 'package:zfth/pages/thAlarm/ThAlarmHandleList.dart';
import 'package:zfth/pages/thAlarm/ThAlarmLogList.dart';
import 'package:zfth/pages/trendAlarm/TrendAlarmHandleList.dart';
import '../../../utils/Settings.dart';
import 'package:get/get.dart';

import '../../components/list/LCellListLogic.dart';


class SmokeAlarmTabPage extends StatefulWidget{

  const SmokeAlarmTabPage({super.key});

  @override
  State<SmokeAlarmTabPage> createState() =>SmokeAlarmTabState();

}

class SmokeAlarmTabState extends State<SmokeAlarmTabPage> with SingleTickerProviderStateMixin{

  late TabController tabController;

  @override
  void initState() {
    tabController = TabController(length: 2, vsync: this);
    tabController.addListener((){//监听滑动或者点击
      if(tabController.index==0){
        if(Get.find<LCellListLogic>(tag: "smokeAlarmHandleList")!=null){
          Get.find<LCellListLogic>(tag: "smokeAlarmHandleList").onRefresh();
        }
      }else if(tabController.index==1){
        if(Get.find<LCellListLogic>(tag: "smokeAlarmLogList")!=null){
          Get.find<LCellListLogic>(tag: "smokeAlarmLogList").onRefresh();
        }
      }
    });
    super.initState();
  }



  @override
  void dispose() {
    tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Settings.backgroundColor,
      appBar: AppBar(
          title: const Text("烟感报警"),
          centerTitle: true,
          elevation: 0,
          bottom:  PreferredSize(
            preferredSize: const Size.fromHeight(48),
            child: Material(
              color: Colors.white,
              child: TabBar(
                controller: tabController,
                indicatorColor: Settings.primaryColor,
                indicatorWeight: 2,
                indicatorPadding: const EdgeInsets.all(2),
                unselectedLabelColor: const Color.fromRGBO(51, 51, 51, 1),
                labelColor: Settings.primaryColor,
                tabs: const [
                  Tab(child: Text("报警处理"),),
                  Tab(child: Text("报警记录"),),
                ],
              ),
            ),
          )

      ),
      body: TabBarView(
        controller: tabController,
        children:const [
          SmokeAlarmHandleListPage(),
          SmokeAlarmLogListPage(),
          // EmpPhoneNeedDownPage()
        ],
      ),
    );
  }

}